import * as questionsApi from '@/api/hmmm/questions'

const state = {
  // 基础题库列表
  questionsList: [],
  // 基础题库详情
  questionsDetails: {},
  // 精选题库列表
  choicenessQuestionsList: []
}

const mutations = {
  // 基础题库列表
  SET_QUESTIONS_LIST (state, newValue) {
    state.questionsList = newValue
  },
  // 基础题库详情
  SET_QUESTIONS_DETAILS (state, newValue) {
    state.questionsDetails = newValue
  },
  // 精选题库列表
  SET_CHOICENESS_QUESTIONS_LIST (state, newValue) {
    state.choicenessQuestionsList = newValue
  }
}

const actions = {
  // 基础题库列表
  async updateQuestionsList ({ commit }) {
    const res = await questionsApi.list()
    commit('SET_QUESTIONS_LIST', res)
  },
  // 基础题库详情
  async updateQuestionsDetails ({ commit }, data) {
    const res = await questionsApi.detail(data)
    commit('SET_QUESTIONS_DETAILS', res)
  },
  // 精选题库
  async updateChoicenessQuestionsList ({ commit }) {
    const res = await questionsApi.choice()
    commit('SET_CHOICENESS_QUESTIONS_LIST', res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
